import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

import '../../../dialog/dailog.dart';
import '../public/acom/ui_workreview_item_info.dart';
import '../public/acom/ui_workreview_scheduling.dart';
import '../public/items/ui_dispatchingaudit.dart';
import '../public/items/ui_workreview.dart';
import 'item/ui_percentage.dart';
import 'item/ui_percentage_acount.dart';
import 'item/ui_percentage_form.dart';

///提成审核详情
class PercentageCheckDetailsRoute extends StatefulWidget {
  PercentageCheckDetailsRoute();

  @override
  _State createState() => _State();
}

class _State extends State<PercentageCheckDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context,
        callback: () {}); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    var PercentageCheck = presenter?.mDatas?.PercentageCheck;
    List<Widget> children = [];
    children.add(UiPercentageCheck.build(
        context,
        presenter?.mDatas?.PercentageCheck,
        presenter?.mOldDatas?.PercentageCheck)); //基本信息
    children.add(UiPercentageCheckAcount.build(
        context,
        presenter?.mDatas?.PercentageCheck,
        presenter?.mOldDatas?.PercentageCheck)); //金额信息
    children
        .add(UiPercentageCheckForm.build(context, PercentageCheck)); //提成审核详情
    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    var hasBack = true;
    var hasAgree = true;
    if (PercentageCheck?.isN6016_1() ?? false) {
      hasBack = false; //已经退回，就不需要退回选项了。
      hasAgree = false;
    }
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              hasAgree: hasAgree,
              hasBack: hasBack,
              hasEnd: false,
              callbackWithT: (subData) {
                //fixme 提交参数数据
                subData.PercentageCheckInfo =
                    PercentageCheck?.PercentageCheckInfo;
              },
              callbackWithBoolResult: () {
                //fixme 提交数据格式验证
                // if (StringUtils.isEmptyWithNumber(
                //     presenter?.mDatas?.OtherWorkApply?.Amount)) {
                //   AppDialog.showDialogWithInfo(context,
                //       content: AppStrings.of(context)
                //           .ApplicationAmountNotEmpty2); //fixme 申请保底金额不能为空
                //   return false;
                // }
                return true;
              },
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
